
<template> 
    <div class="profile">
        <div class="header">个人资料</div>
        <div class="title">这里是用户的个人资料信息</div>
        <div class="content">
            <!-- 昵称 -->
            <div class="item">
                昵称：<input type="text" v-model="profileData.name" class="input" />
            </div>
            <!-- 邮箱 -->
            <div class="item">
                邮箱：<input type="text" v-model="profileData.email" class="input" />
            </div>
            <!-- 手机号 -->
            <div class="item">
                电话：<input type="text" v-model="profileData.phone" class="input" />
            </div>
            <!-- 地址 -->
            <div class="item">
                地址：<input type="text" v-model="profileData.address" class="input" />
            </div>
            <!-- 留言 -->
            <div class="item">
                留言：<input type="text" v-model="profileData.message" class="input" />
            </div>
        </div>
        <button class="button" @click="updateProfile()">保存</button>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router';

// Router是路由实例
const router = useRouter();
const profileData = ref({
    name: "",
    email: "",
    phone: "",
    address: "",
    message: ""
});
function updateProfile() {
    console.log("更新个人资料:", profileData.value);
    if(!profileData.value.name || !profileData.value.email || !profileData.value.phone || !profileData.value.address || !profileData.value.message) {
        alert("请输入完整的个人资料");
        return;
    }
    // 进行保存，使用localStorage，setItem,JSON.stringify将js对象转换为字符串
    localStorage.setItem("profileData", JSON.stringify(profileData.value));
    alert("个人资料已保存");
    // 跳转
    router.push("/updateProfile");
}

</script>

<style lang="css" scoped>
* {
    margin: 0;
    padding: 0;
}

.profile {
    font-family: Arial, Helvetica, sans-serif;
    text-align: center;
}

.header {
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    margin: 10px 0px 10px 0px;
}

.title {
    font-size: 14px;
    color: rgb(168, 168, 168);
    text-align: center;
    margin-bottom: 10px;
}

.content {
    padding: 10px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #fff;
}

.item {
    background-color: #fffbf6;
    padding: 20px 0 20px 0;
    font-size: 20px;
}

.input {
    /* 无上、左、右边框 */
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: red 2px solid;
}

.button {
    width: 180px;
    height: 45px;
    background: linear-gradient(135deg, #e0fde1, #81C784);
    font-size: 20px;
    border-radius: 20px;
}
</style>